<?php
    Class Dashboard_model extends CI_Model
    {
    	public function __construct()
    	{
    		parent::__construct();
    	}

    	public function getImportHistory($from_date = false, $to_date = false)
    	{
    		$sql = "SELECT DATE(date_created) as 'day', COUNT(id) as 'import' 
					FROM `history`  
					WHERE type = 1 
					AND date_created BETWEEN '$from_date' AND '$to_date' 
					GROUP BY DATE(date_created)";
			
			$query = $this->db->query($sql);						

			return $query->result();
    	}

    	public function getExportHistory($from_date = false, $to_date = false)
    	{
    		$sql = "SELECT DATE(date_created) as 'day', COUNT(id) as 'export' 
					FROM `history`  
					WHERE type = 2 
					AND date_created BETWEEN '$from_date' AND '$to_date' 
					GROUP BY DATE(date_created)";
			
			$query = $this->db->query($sql);			

			return $query->result();
    	}

        public function countAll($type = false)
        {
            $this->db->select('*');
            $this->db->from('history');
            $this->db->where('type',$type);
            return $this->db->count_all_results();
        }
    }
?>    	